<template>
  <div class="article-content-area">
    <van-nav-bar
      title="详情页"
      size="18"
      left-text=""
      right-text=""
      left-arrow
      @click-left="onClickLeft"
    />
    <div class="main-content-area" v-if="processInstance">
      <div class="top-tit">
        <strong class="title-h1">{{ processInstance.name }}</strong>
        <span class="title-time">{{
          parseTime(processInstance.createTime)
        }}</span>
      </div>
      <div class="main-content">
        <div class="inner-main-content" v-html="formattedXml"></div>
      </div>
    </div>
  </div>
</template>
<script>
import { Toast } from "vant";
import { getProcessInstance } from "@/api/bpm/processInstance";
export default {
  name: "ProductList",
  data() {
    return {
      id: "",
      processInstance: null,
      rawXml: "",
    };
  },
  computed: {
    formattedXml() {
      return this.formatXml(this.rawXml);
    },
  },
  created() {
    this.id = this.$route.query.id;
    this.getDetail(this.id);
  },
  methods: {
    formatXml(xml) {
      const parser = new DOMParser();
      const xmlDoc = parser.parseFromString(xml, "text/xml");
      return xmlDoc.documentElement.outerHTML;
    },
    async getDetail(id) {
      const res = await getProcessInstance(id);
      if (!res.data) {
        Toast("查询不到流程信息！");
        return;
      }
      // 设置流程信息
      this.processInstance = res.data;
      this.rawXml = res.data.processDefinition.bpmnXml;
    },
    onClickLeft() {
      this.$router.go(-1);
    },
  },
};
</script>
<style lang="scss">
.article-content-area {
  padding-bottom: 50px;
  width: 100vw;
  height: 100vh;
  background: #fff;

  .main-content-area {
    padding: 20px 16px 0px 16px;

    .main-content {
      max-height: 700px;
      overflow: auto;
      padding: 0 0 30px 0;
    }
    img {
      width: 343px;
      height: auto;
    }
    .top-tit {
      margin: 0 0 20px 0;
      .title-h1 {
        font-weight: 700;
        font-size: 14px;
        color: #222222;
        line-height: 20px;
        text-align: left;
        display: block;
      }

      .title-time {
        font-size: 12px;
        color: #999999;
        line-height: 17px;
      }
    }

    .row-p {
      text-indent: 2em;
      font-weight: 400;
      font-size: 12px;
      color: #666666;
      line-height: 26px;
      text-align: left;
    }
    .img-area {
      margin: 10px 0;
    }
  }
}
</style>
